//------------------------------------------------------------
//ContactManager.java
//------------------------------------------------------------

import java.awt.*;
import javax.swing.*;

public class ContactManager {

	private static JLabel welcome, pwlabel;
	private static JPasswordField pwdfld;
	private static JPanel pan;

	public static void main(String[] args) {

		ContactCollection contact = new ContactCollection();
		contact.loadPW();

		pwdfld = new JPasswordField(15);
		pwdfld.setFont(new Font("맑은 고딕", Font.PLAIN, 14));
		pwdfld.setBackground(new Color(204, 255, 255));
		welcome = new JLabel("Welcome To Kiyong's ContactBook!");
		welcome.setAlignmentX(Component.CENTER_ALIGNMENT);
		welcome.setFont(new Font("맑은 고딕", Font.BOLD, 18));
		pwlabel = new JLabel("비밀번호를 입력해주세요.");
		pwlabel.setAlignmentY(0.4f);
		pwlabel.setAlignmentX(Component.CENTER_ALIGNMENT);
		pwlabel.setFont(new Font("맑은 고딕", Font.PLAIN, 14));
		pan = new JPanel();
		pan.setBackground(UIManager.getColor("Button.background"));
		pan.setLayout(new BoxLayout(pan, BoxLayout.Y_AXIS));
		pan.add(Box.createRigidArea(new Dimension(0, 20)));
		pan.add(welcome);
		pan.add(Box.createRigidArea(new Dimension(0, 20)));
		pan.add(pwlabel);
		pan.add(Box.createRigidArea(new Dimension(0, 20)));
		pan.add(pwdfld);

		int action = JOptionPane.showOptionDialog(null, pan, "비밀번호 입력창",JOptionPane.DEFAULT_OPTION,
				     JOptionPane.INFORMATION_MESSAGE, null, null, null);

		if (action < 0)
			System.exit(0);
		else {
			String password = new String(pwdfld.getPassword());
			if (contact.IdentifyPW(password)) {
				if (password.equals("000000"))
					JOptionPane.showMessageDialog(null,
							"000000이 아닌 다른 비밀번호로 바꿔주세요^^*");
				JFrame frame = new JFrame("Kiyong's Contactbook");
				frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				frame.getContentPane().add(new ContactManagerPanel());
				frame.pack();
				frame.setVisible(true);
			} 
			else
				JOptionPane.showMessageDialog(null, "잘못된 비밀번호입니다.");
		}
	}
}
